package com.Adapter;


import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import com.BD.Tabla_Evento;
 
import android.R.integer;
import android.app.TabActivity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListAdapter;
 
public class ImageAdapter_Eventos extends BaseAdapter implements ListAdapter {
 
    private Context context;
    private ArrayList<Tabla_Evento> tablaEventos;
    
    public ImageAdapter_Eventos(ArrayList<Tabla_Evento> te, Context context) {
        super();
        this.context = context;
        this.tablaEventos = te;
    }
    
     
    @Override
    public int getCount() {
        return tablaEventos.size();
    }
 
    @Override
    public Object getItem(int position) {
 
        return tablaEventos.get(position);
    }
 
    @Override
    public long getItemId(int position) {
         
        return position;
    }
 
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView;
        if(convertView==null)
        {
            imageView=new ImageView(context);
            imageView.setLayoutParams(new GridView.LayoutParams(190,190));
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setPadding(5,5,5,5);
        }else{
            imageView=(ImageView)convertView;
        }
        try {
			imageView.setImageDrawable((new ImageDownloader().execute(tablaEventos.get(position).getUrlEvento())).get());
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        //imageView.setImageDrawable(LoadImageFromURL(tablaSubTipo.get(position).getUrl()));
        Log.e("url:", tablaEventos.get(position).getUrlEvento());
        return imageView;
    }
     
 
}